<template>  
  <div>  
    <h2>Login</h2>  
    <form @submit.prevent="handleSubmit">  
      <input type="text" v-model="username" placeholder="Username" required />  
      <input type="password" v-model="password" placeholder="Password" required />  
      <button type="submit">Login</button>  
    </form>  
  </div>  
</template>  
  
<script>  
export default {  
  data() {  
    return {  
      username: '',  
      password: ''  
    };  
  },  
  methods: {  
    handleSubmit() {  
      // 假设用户名是 "admin"，密码是 "password"  
      if (this.username === 'admin' && this.password === 'password') {  
        // 登录成功，将用户信息保存到 localStorage  
        localStorage.setItem('user', JSON.stringify({ username: this.username }));  
        this.$router.push('/'); // 重定向到首页或其他页面  
      } else {  
        alert('Invalid username or password');  
      }  
    }  
  }  
};  
</script>